<!DOCTYPE html>
<html>
<script type="text/javascript" src="lib/prototype.js"></script>
<script type="text/javascript">
	var val = function(val, def) {
		def = Object.isUndefined(def) ? false : def;
		if (Object.isUndefined(localStorage[val]) == false) {
			if (Object.isNumber(def)) {
				return localStorage[val];
			} else {
				return (localStorage[val] == "true") ? true : false;
			}
		} else {
			localStorage[val] = def;
			return def;
		}
	};

	chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
		if (request.method == "getOptions") {
			sendResponse({
				data : {
					debug : false,
					updateEnabled : val("updateEnabled", true),
					updateInterval : val("updateInterval", 10),
					showExtraButtons : val("showExtraButtons"),
					postPreview : val("postPreview"),
					reorderTitle : val("reorderTitle"),
					reorderStreamTitle : val("reorderStreamTitle"),
					showResetButton : val("showResetButton"),
					updateLastForumThreads : val("updateLastForumThreads"),
					ajaxSubmit : val("ajaxSubmit"),
					ajaxEdit : val("ajaxEdit"),
					listenForPM : val("listenForPM"),
					darkStyle : val("darkStyle"),
					spoilerLongPosts : val("spoilerLongPosts"),
					spoilerLongPostsRows : val("spoilerLongPostsRows", 200),
					hideNews : val("hideNews"),
					jumpToLastPost : val("jumpToLastPost"),
					infiniteScrolling : val("infiniteScrolling"),
					newPostColor : localStorage["newPostColor"] || "#ffff00",
					headlines : [ [ "cs", val("hlCs", true) ], [ "sc", val("hlSc", true) ], [ "dota", val("hlDota", true) ], [ "lol", val("hlLol", true) ], [ "wc3", val("hlWc3", true) ], [ "other", val("hlOther", true) ] ]
				}
			});
		} else if (request.method == "showNotification") {
			chrome.permissions.contains({
				permissions : [ "notifications" ]
			}, function(result) {
				if (result) {
					var text;
					if (request.msgCount > 1) {
						text = "neue Nachrichten.";
					} else {
						text = "neue Nachricht.";
					}
					webkitNotifications.createNotification("readmore.jpg", "readmore - Neue Nachricht", "Du hast " + request.msgCount + " " + text).show();
				}
			});
		} else {
			sendResponse({});
		}
	});
</script>
</html>